
<template>
  <!-- 账簿维护/经费账录入 页面-->
  <div>

    <cus-allcard :showTitle="false" style="min-width:924px;">

      <Tabs :value="tabsValue" @on-click="tabsValueChange($event)" style="padding-top:16px;min-width:880px;">
        <Tab-pane label="经费账录入" name="nameOne">
          <div class="topBody">
            <div class="topBodyItem">
              <span class="itemSpan">账簿年度</span>
              <Input v-model="selectForm.year" class="itemImport" :disabled="true" placeholder="请输入账簿年度"
                maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">凭证号码</span>
              <Input v-model="selectForm.certificatesn" class="itemImport" :disabled="true" placeholder="请输入凭证号码"
                maxlength="15"></Input>
            </div>
            <!-- 暂时去掉 -->
            <!-- <div class="topBodyItem">
              <span class="itemSpan">业务类型：</span>
              <Select v-model="selectForm.businesstypeOne"
                      size="large"
                      placeholder="请选择业务类型"
                      @on-change="selectModelChangeOne()"
                      class="itemImport">
                <Option v-for="item in selectForm.businesstypeOneList"
                        :value="item.businesstype"
                        :key="item.abstractId">{{ item.businesstype }}</Option>
              </Select>
            </div> -->
            <div class="topBodyItem">
              <span class="itemSpan">摘要内容</span>
              <Input v-model="selectForm.abstractnameOne" class="itemImport" placeholder="请输入摘要内容" maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">入账日期</span>
              <Date-picker type="date" :options="options" v-model="selectForm.dataTimeOne" :clearable="false"
                placeholder="请选择入账日期" class="itemImport"></Date-picker>
            </div>

            <div class="topBodyItem">
              <span class="itemSpan">备注信息</span>
              <Input v-model="selectForm.remarkOne" class="itemImport" placeholder="请输入备注信息" maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <cus-Button type="primary" :disabled="!selectForm.year" @onClick="addModelChangeOne" class="ml_20"
                v-permission="20">入账</cus-Button>
            </div>
            <div class="topBodyItem">
              <cus-Button type="primary" style="margin-left" :disabled="!selectForm.year" @onClick="addDataOneItem"
                v-permission="20">添加科目</cus-Button>
            </div>

          </div>
          <cusTable border :loading="form.loading" :columns="columnsOne" :data="dataOne" :size="vuex_config.tableSize">

            <template slot-scope="{ row, index }" slot="subjectFullName">
              <div style="padding:18px 0px;">
                <Select v-model="row.subjectFullName" placeholder="请选择科目" :transfer="true" style="max-width:200px"
                  @on-change="subjectNameOne(index, row.subjectFullName)">
                  <Option v-for="item in subjectlistOne" :value="item.subjectfullname" :key="item.subjectfullname">{{
                    item.subjectfullname }}</Option>
                </Select>

              </div>
            </template>
            <template slot-scope="{ row, index }" slot="direction">
              <div style="padding:18px 0px;">
                <Select v-model="row.direction" :transfer="true" style="max-width:200px" placeholder=""
                  @on-change="directionOne(index, row.direction)">
                  <Option :value="0">收</Option>
                  <Option :value="1">付</Option>
                </Select>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="recMoney">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.recMoney" v-if="row.direction != 1" :min="0" :max="999999999" style="width:100%;" precision="2" :active-change="false"
                  @on-change="recMoneyOne(index, row.recMoney)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 1">{{ row.recMoney }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="payMoney">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.payMoney" v-if="row.direction != 0" :min="0" :max="999999999" style="width:100%" precision="2" :active-change="false"
                  @on-change="payMoneyOne(index, row.payMoney)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 0">{{ row.payMoney }}</span>
              </div>
            </template>
            <template slot-scope="{ index }" slot="operation">
              <div class="flex">
                <cus-button type="text" size="small" style='color:#FF4746;padding:0 8px;' @onClick="clearCliOne(index)">
                  删除
                </cus-button>
              </div>
            </template>
          </cusTable>

        </Tab-pane>
        <Tab-pane label="粮秣账录入" name="nameTwo">
          <div class="topBody">
            <div class="topBodyItem">
              <span class="itemSpan">账簿年度</span>
              <Input v-model="selectForm.year" class="itemImport"  :disabled="true" placeholder="请输入账簿年度"
                maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">凭证号码</span>
              <Input v-model="selectForm.certificatesn" class="itemImport" :disabled="true" placeholder="请输入凭证号码"
                maxlength="15"></Input>
            </div>
            <!-- 暂时去掉 -->
            <!-- <div class="topBodyItem">
              <span class="itemSpan">业务类型：</span>
              <Select v-model="selectForm.businesstypeTwo"
                      size="large"
                      placeholder="请选择业务类型"
                      @on-change="selectModelChangeTwo()"
                      class="itemImport">
                <Option v-for="item in selectForm.businesstypeTwoList"
                        :value="item.businesstype"
                        :key="item.abstractcode">{{ item.businesstype }}</Option>
              </Select>
            </div> -->
            <div class="topBodyItem">
              <span class="itemSpan">摘要内容</span>
              <Input v-model="selectForm.abstractnameTwo" class="itemImport" placeholder="请输入摘要内容" maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">入账日期</span>
              <Date-picker type="date" :options="options" v-model="selectForm.dataTimeTwo" :clearable="false" placeholder="请选择入账日期"
                class="itemImport"></Date-picker>
            </div>

            <div class="topBodyItem">
              <span class="itemSpan">备注信息</span>
              <Input v-model="selectForm.remarkTwo" class="itemImport" placeholder="请输入备注信息" maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <cus-Button type="primary" :disabled="!selectForm.year" @onClick="addModelChangeTwo" class="ml_20"
                v-permission="20">入账</cus-Button>
            </div>
            <div class="topBodyItem">
              <cus-Button type="primary" style="margin-left" :disabled="!selectForm.year" @onClick="addDataTwoItem"
                v-permission="20">添加科目</cus-Button>
            </div>
          </div>
          <cusTable border :loading="form.loading" :columns="columnsTwo" :data="dataTwo"
            :height="dataTwo.length == 0 ? '127' : tableHeight > dataTwo.length * 87 + 50 ? dataTwo.length * 87 + 50 : tableHeight"
            :size="vuex_config.tableSize">
            <template slot-scope="{ row, index }" slot="subjectFullName">
              <div style="padding:18px 0px;">
                <Select v-model="row.subjectFullName" placeholder="请选择科目" :transfer="true" style="max-width:200px"
                  @on-change="subjectNameTwo(index, row.subjectFullName)">

                  <Option v-for="item in subjectlistTwo" :value="item.subjectfullname" :key="item.abstractId">{{
                    item.subjectfullname }}</Option>
                </Select>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="direction">
              <div style="padding:18px 0px;">
                <Select v-model="row.direction" :transfer="true" placeholder="" style="max-width:200px"
                  @on-change="directionTwo(index, row.direction)">
                  <Option :value="0">收</Option>
                  <Option :value="1">付</Option>
                </Select>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="recrice">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.recrice" v-if="row.direction != 1" :min="0" style="width:100%"
                  @on-change="recriceTwo(index, row.recrice)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 1">{{ row.recrice }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="recflour">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.recflour" v-if="row.direction != 1" :min="0" style="width:100%"
                  @on-change="recflourTwo(index, row.recflour)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 1">{{ row.recflour }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="recoil">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.recoil" v-if="row.direction != 1" :min="0" style="width:100%"
                  @on-change="recoilTwo(index, row.recoil)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 1">{{ row.recoil }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="recbean">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.recbean" v-if="row.direction != 1" :min="0" style="width:100%"
                  @on-change="recbeanTwo(index, row.recbean)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 1">{{ row.recbean }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="payrice">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.payrice" v-if="row.direction != 0" :min="0" style="width:100%"
                  @on-change="payriceTwo(index, row.payrice)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 0">{{ row.payrice }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="payflour">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.payflour" v-if="row.direction != 0" :min="0" style="width:100%"
                  @on-change="payflourTwo(index, row.payflour)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 0">{{ row.payflour }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="payoil">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.payoil" v-if="row.direction != 0" :min="0" style="width:100%"
                  @on-change="payoilTwo(index, row.payoil)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 0">{{ row.payoil }}</span>
              </div>
            </template>
            <template slot-scope="{ row, index }" slot="paybean">
              <div class="tableInput" style="padding:18px 0px;">
                <Input-number v-model="row.paybean" v-if="row.direction != 0" :min="0" style="width:100%"
                  @on-change="paybeanTwo(index, row.paybean)" placeholder="输入金额"></Input-number>
                <span v-if="row.direction == 0">{{ row.paybean }}</span>
              </div>
            </template>
            <template slot-scope="{ index }" slot="operation">
              <div class="flex">
                <cus-button type="text" size="small" style='color:#FF4746;padding:0 8px;' @onClick="clearCliTwo(index)">
                  删除
                </cus-button>
              </div>
            </template>
          </cusTable>

        </Tab-pane>
      </Tabs>

    </cus-allcard>
    <!-- 使用粘性定位 -->
    <div v-if="superiorState" class="sticky-button">
      <cus-Button class="mr_10" type="default" @onClick="returnHome">返回首页</cus-Button>
    </div>
  </div>
</template>
<script>
import {
  getAccountBook,
  getLastCertSn,
  getAbstractByAccountBookIdAndType,
  getSubjectToCertificate,
  addCertificateInfo
} from '@/api/businessAccountingApi/essentialInformationApi'
export default {
  data() {
    return {
      options: {
        disabledDate: (date) => {
          let beginT = new Date(`${this.selectForm.year}-01-01`).getTime();
          let currentY = new Date().getFullYear();
          if (currentY == this.selectForm.year) {
            return date && (beginT - 86400000 > date.valueOf() || date.valueOf() >= Date.now());
          } else {
            let endT = new Date(`${parseInt(this.selectForm.year) + 1}-01-01`).getTime() - 86400000;
            return date && (beginT - 86400000 > date.valueOf() || date.valueOf() >= endT);
          }
        }
      },
      superiorState: false,
      tabsValue: 'nameOne',
      form: {
        loading: false,
        name: '',
        startTime: '',
        endTime: ''
      },
      // 查询条件的集合
      selectForm: {
        year: null, // 账簿时间
        accountbookId: null, // 账簿id
        department: null, // 部门名称
        certificatesn: null, // 凭证号码
        dataTimeOne: null, // 入账日期-经费账
        dataTimeTwo: null, // 入账日期-粮秣账
        businesstypeOneList: [], // 业务类型-经费账列表
        businesstypeOne: null, // 业务类型-经费账
        businesstypeTwoList: [], // 业务类型-粮秣账列表
        businesstypeTwo: null, // 业务类型-粮秣账
        abstractnameOne: null, // 摘要内容-经费账
        abstractnameTwo: null, // 摘要内容-粮秣账
        remarkOne: '', // 备注信息-经费账
        remarkTwo: '' // 备注信息-经费账
      },

      subjecttype: 0, // 0经费账 1粮秣账
      // 经费账表格每次添加的初始模板
      dataOneItem: {
        subjectId: null, // 科目id
        subjectCode: null, // 科目编码
        subjectName: null, // 科目名称
        subjectFullName: null, //科目名称
        direction: null, // 收付(0-收，1-付)
        recMoney: 0, // 收方金额
        payMoney: 0 // 付方金额
      },
      dataOne: [], // 经费账-表格列表
      subjectlistOne: [], // 表格科目名称选择器列表 -经费账
      subjectlistTwo: [], // 表格科目名称选择器列表 -粮秣账
      // 经费账-表头
      columnsOne: [
        {
          title: '科目名称',
          slot: 'subjectFullName',
          align: 'center',
          minWidth: 180
        },
        {
          title: '收(付)',
          slot: 'direction',
          align: 'center',
          minWidth: 80
        },
        {
          title: '收方金额(元)',
          slot: 'recMoney',
          align: 'center',
          minWidth: 120
        },
        {
          title: '付方金额(元)',
          slot: 'payMoney',
          align: 'center',
          minWidth: 120
        },
        {
          title: '操作',
          fixed: 'right', // 右侧固定
          slot: 'operation',
          align: 'center',
          minWidth: 100
        }
      ],
      // 粮秣表格每次添加的初始模板
      dataTwoItem: {
        subjectId: null, // 科目id
        subjectCode: null, // 科目编码
        subjectName: null, // 科目名称
        subjectFullName: null, //科目名称
        direction: null, // 收付(0-收，1-付)
        recrice: 0, // 收方大米重量（千克）粮秣账必传
        recflour: 0, // 收方小麦粉（千克） 粮秣账必传
        recoil: 0, // 收方石油（千克） 粮秣账必传
        recbean: 0, // 收付大豆（千克） 粮秣账必传
        payrice: 0, // 付方大米重量（千克） 粮秣账必传
        payflour: 0, // 付方小麦粉（千克） 粮秣账必传
        payoil: 0, // 付方石油（千克） 粮秣账必传
        paybean: 0 // 付方大豆（千克） 粮秣账必传
      },
      dataTwo: [], // 粮秣账-表格列表
      // 粮秣账-表头
      columnsTwo: [
        {
          title: '科目名称',
          slot: 'subjectFullName',
          align: 'center',
          minWidth: 180
        },
        {
          title: '收(付)',
          slot: 'direction',
          align: 'center',
          minWidth: 100
        },
        {
          title: '收方(大米)',
          slot: 'recrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '收方(小麦粉)',
          slot: 'recflour',
          align: 'center',
          minWidth: 120
        },
        {
          title: '收方(食油)',
          slot: 'recoil',
          align: 'center',
          minWidth: 120
        },
        {
          title: '收方(大豆)',
          slot: 'recbean',
          align: 'center',
          minWidth: 120
        },
        {
          title: '付方(大米)',
          slot: 'payrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '付方(小麦粉)',
          slot: 'payflour',
          align: 'center',
          minWidth: 120
        },
        {
          title: '付方(食油)',
          slot: 'payoil',
          align: 'center',
          minWidth: 120
        },
        {
          title: '付方(大豆)',
          slot: 'paybean',
          align: 'center',
          minWidth: 120
        },

        {
          title: '操作',
          fixed: 'right',
          slot: 'operation',
          align: 'center',
          minWidth: 100
        }
      ],
      subjectid: 0, // 删除经费账粮秣账接口传参id
      tableHeight: 0
    }
  },
  mounted() {
    setTimeout(() => {
      this.tableHeight = window.innerHeight - 64 - 40 - 16 - 37 - 16 - 108 - 24 - 40// 表格自适应高度
    }, 100)
    window.addEventListener('resize', this.tableHeightChange, true)
    this.selectForm.dataTimeOne = new Date().Format('yyyy-MM-dd')
    this.selectForm.dataTimeTwo = new Date().Format('yyyy-MM-dd')
    this.getAccountBookApi() // 查询活动账簿 接口
    this.addDataOneItem()
    // this.addDataOneItem()
    this.addDataTwoItem()
    // this.addDataTwoItem()

    // 函数时提示变成3秒消失
    this.$Message.config({
      top: 50,
      duration: 3
    })
    // this.getAccountBookListByUserApi() // 根据用户id查询账簿-选择器使用
    // this.getAllSubjectApi(0)// 默认查经费账     // 获取 经费账录入 或 粮秣账录入
  },
  // 销毁函数时提示变回1.5秒消失
  beforeDestroy() {
    this.$Message.config({
      top: 50,
      duration: 1.5
    })
  },
  destroyed() {
    window.removeEventListener('resize', this.tableHeightChange, true)
  },
  activated() {
    if (this.$route.query.superior == 'home') {
      this.superiorState = true
    } else {
      this.superiorState = false
    }
  },
  methods: {
    tableHeightChange() {
      this.tableHeight = 0
      setTimeout(() => {
        this.tableHeight = window.innerHeight - 64 - 40 - 16 - 37 - 16 - 108 - 24 - 40// 表格自适应高度
      }, 100)
    },
    // 查询活动账簿 接口
    getAccountBookApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getAccountBook({
          userid: this.vuex_user.base.id // 用户id
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.selectForm.year = res.basAccountbook.year // 账簿年度-回显使用
            this.selectForm.accountbookId = res.basAccountbook.accountbookId // 账簿id
            // this.selectForm.department = res.basAccountbook.department // 部门名称 查询凭证号码接口传参使用 后台要求先传空
            this.selectForm.department = '' // 部门名称 查询凭证号码接口传参使用 后台要求先传空
            this.getLastCertSnApi()// 查询凭证号码 接口
            this.getSubjectToCertificateApi()// 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 查询凭证号码 接口
    getLastCertSnApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getLastCertSn({
          accountyear: this.selectForm.year, // 账簿年度
          department: this.selectForm.department, // 部门名称
          userid: this.vuex_user.base.id // 用户id
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.selectForm.certificatesn = (res.lastcertsn + 1).toString()
            this.getAbstractByAccountBookIdAndTypeApi()// 根据类型、账簿id查询业务类型(不分页)  接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 根据类型、账簿id查询业务类型(不分页)  接口
    getAbstractByAccountBookIdAndTypeApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getAbstractByAccountBookIdAndType({
          userid: this.vuex_user.base.id, // 用户id
          accountBookId: this.selectForm.accountbookId, // 账簿id
          iszhineng: 0,
          abstractType: this.subjecttype //  摘要内容(0经费;1粮秣)
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            if (this.subjecttype === 0) { // 经费账
              this.selectForm.businesstypeOneList = res.abstractlist // 业务类型-经费账列表
            } else { // 粮秣账
              this.selectForm.businesstypeTwoList = res.abstractlist // 业务类型-粮秣账列表
            }
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
    getSubjectToCertificateApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getSubjectToCertificate({
          userid: this.vuex_user.base.id, // 用户id
          accountBookId: this.selectForm.accountbookId, // 账簿id
          subjectType: this.subjecttype //  摘要内容(0经费;1粮秣)
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            if (this.subjecttype === 0) { // 经费账
              this.subjectlistOne = res.subjectlist // 表格科目名称选择器列表 -经费账
            } else { // 粮秣账
              this.subjectlistTwo = res.subjectlist // 表格科目名称选择器列表 -粮秣账
            }
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },

    // tabs标签页改变回调
    tabsValueChange(value) {
      if (value === 'nameOne') { // 经费账录入
        this.subjecttype = 0 // 全局标明为经费账
        this.getAccountBookApi()// 查询活动账簿 接口
        // this.getAbstractByAccountBookIdAndTypeApi()// 根据账簿id和类型查询摘要(不分页) 接口
        // this.getSubjectToCertificateApi() // 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
      } else { // 粮秣账录入
        this.subjecttype = 1// 全局标明为粮秣
        this.getAccountBookApi()// 查询活动账簿 接口
        // this.getAbstractByAccountBookIdAndTypeApi()// 根据账簿id和类型查询摘要(不分页) 接口
        // this.getSubjectToCertificateApi() // 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
      }
    },
    // 入账按钮-经费账
    addModelChangeOne() {
      // 判断表格里是否有空的值，有不往下执行
      let ass = false
      // 暂时去掉
      // if (!this.selectForm.businesstypeOne) {
      //   this.$Message.info('业务类型不能为空')
      //   return
      // }
      if (!this.selectForm.abstractnameOne) {
        this.$Message.info('摘要内容不能为空')
        return
      }
      this.dataOne.forEach((element, index) => {
        console.log(index);
        if (element.subjectFullName === null || element.subjectFullName === '' || element.subjectFullName === undefined) {
          this.$Message.info(`表格${index + 1}科目名称为空不能保存`)
          ass = true
          throw Error();
        }
        if (element.direction === null || element.direction === '' || element.direction === undefined) {
          this.$Message.info(`表格${index + 1}收(付)为空不能保存`)
          ass = true
          throw Error();
        } else if (element.direction === 1) { // 付
          if (element.payMoney === null || element.payMoney === 0 || element.payMoney === undefined) {
            this.$Message.info('表格付方金额为空不能保存')
            ass = true
            throw Error();
          }
        } else if (element.direction === 0) { // 收
          if (element.recMoney === null || element.recMoney === 0 || element.recMoney === undefined) {
            this.$Message.info('表格收方金额为空不能保存')
            ass = true
            throw Error();
          }
        }
      })
      if (ass) {
        return
      }
      let isTrueFalse = false
      // 定义一个新数组
      const newArr = []
      this.dataOne.forEach(element => {
        // 定义一个变量存放索引
        let index = newArr.findIndex(v => {
          return element.subjectFullName === v.name
        })
        // 判断index的值 findIndex方法找不到返回-1 找不到就新加上 找到就找到新数组中这个值的位置给他num++
        if (index === -1) {
          newArr.push({ name: element.subjectFullName, num: 1 })
        } else {
          return isTrueFalse = true
        }
      })
      if (isTrueFalse) {
        this.$Message.info('科目存在重复无法入账，请查阅')
        return
      }
      var valueData = {
        accountbookId: this.selectForm.accountbookId, // 账簿id
        isValid: 1, // 是否在用 1-在用，0-没用
        abstractType: this.subjecttype, // 摘要内容:0经费账摘要,1粮秣账摘要,2明细摘要
        subjectType: this.subjecttype, // 科目类型:0经费账科目,1粮秣账科目,2分项核算明细
        accountYear: this.selectForm.year, // 账簿年份
        certificateSn: this.selectForm.certificatesn, // 凭证号码
        isznjzflag: 0, // 智能计账标识  1是0否 2全部
        certificateDate: new Date(this.selectForm.dataTimeOne).Format('yyyy-MM-dd'), // 入账日期  YYYY-mm-DD
        businessType: this.selectForm.businesstypeOne, // 业务类型.可以理解为摘要
        abstractName: this.selectForm.abstractnameOne, // 摘要内容
        department: this.selectForm.department, // 部门.比如一连队
        operatorname: this.vuex_user.base.name, // 登陆人姓名
        operatorid: this.vuex_user.base.id, // 用户id//登陆人Id
        certificatetype: 0, // 凭证类型0-普通，1-结转下年，2-上年转入
        remark: this.selectForm.remarkOne, // 备注
        subjectDtoList: this.dataOne
      }
      this.form.loading = true
      return new Promise((resolve) => {
        addCertificateInfo(valueData).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.dataOne = []
            this.selectForm.abstractnameOne = ''
            this.selectForm.remarkOne = ''
            this.addDataOneItem()
            this.addDataOneItem()
            this.getAccountBookApi() // 查询活动账簿 接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 经费账添加按钮
    addDataOneItem() {
      if (this.dataOne.length > 1) {
        let ass = false
        this.dataOne.forEach((element, index) => {
          if (element.subjectFullName === null || element.subjectFullName === '' || element.subjectFullName === undefined) {
            this.$Message.info('请先填选表格第' + (index + 1) + '条数据中的  科目名称  再进行添加科目')
            ass = true
            return ass
          }
          if (element.direction === null || element.direction === '' || element.direction === undefined) {
            this.$Message.info('请先填选表格第' + (index + 1) + '条数据中的 收（付） 再进行添加科目')
            ass = true
            return ass
          } else if (element.direction === 1) { // 付
            if (element.payMoney === null || element.payMoney === 0 || element.payMoney === undefined) {
              this.$Message.info('请先输入表格第' + (index + 1) + '条数据中的 付方金额 再进行添加科目')
              ass = true
              return ass
            }
          } else if (element.direction === 0) { // 收
            if (element.recMoney === null || element.recMoney === 0 || element.recMoney === undefined) {
              this.$Message.info('请先输入表格第' + (index + 1) + '条数据中的 收方金额 再进行添加科目')
              ass = true
              return ass
            }
          }
        })
        this.dataOne.push(JSON.parse(JSON.stringify(this.dataOneItem)))
        if (ass) {
          this.dataOne.splice(this.dataOne.length - 1, 1)
        }
      } else {
        this.dataOne.push(JSON.parse(JSON.stringify(this.dataOneItem)))
      }
    },
    // 业务类型选择器改变回调-经费账
    selectModelChangeOne() {

    },
    // 表格科目名称改变回调-经费账
    subjectNameOne(index, value) {
      if (value == undefined) {
        return
      }
      this.dataOne[index].subjectFullName = value
      this.subjectlistOne.forEach(element => {
        if (this.dataOne[index].subjectFullName === element.subjectfullname) {
          this.dataOne[index].subjectId = element.subjectId
          this.dataOne[index].subjectCode = element.subjectcode
          this.dataOne[index].subjectName = element.subjectname
        }
      })
      // 定义一个新数组
      const newArr = []
      this.dataOne.forEach(element => {
        // 定义一个变量存放索引
        let index = newArr.findIndex(v => {
          return element.subjectFullName === v.name
        })
        // 判断index的值 findIndex方法找不到返回-1 找不到就新加上 找到就找到新数组中这个值的位置给他num++
        if (index === -1) {
          newArr.push({ name: element.subjectFullName, num: 1 })
        } else {
          this.$Message.info('科目存在重复无法入账，请查阅')
          newArr[index].num++
        }
      })
    },
    // 表格科目方向改变回调-经费账
    directionOne(index, value) {
      this.dataOne[index].direction = value
      this.dataOne[index].recMoney = 0
      this.dataOne[index].payMoney = 0
    },
    // 收方金额(元)改变回调-经费账
    recMoneyOne(index, value) {
      this.dataOne[index].recMoney = value
    },
    // 收方金额(元)改变回调-经费账
    payMoneyOne(index, value) {
      this.dataOne[index].payMoney = value
    },
    // 经费账表格清除按钮
    clearCliOne(index) {
      this.dataOne.splice(index, 1)
      if (this.dataOne.length < 2) {
        this.addDataOneItem()
        this.$Message.info('至少存在两个科目！')
      }
      // this.zhi.splice(index, 1)
    },
    // 入账按钮-粮秣账
    addModelChangeTwo() {
      // 判断表格里是否有空的值，有不往下执行
      let ass = false
      // 暂时去掉
      // if (!this.selectForm.businesstypeTwo) {
      //   this.$Message.info('业务类型不能为空')
      //   return
      // }
      if (!this.selectForm.abstractnameTwo) {
        this.$Message.info('摘要内容不能为空')
        return
      }
      this.dataTwo.forEach(element => {
        if (element.subjectFullName === null || element.subjectFullName === '' || element.subjectFullName === undefined) {
          this.$Message.info('表格科目名称为空不能保存')
          ass = true
          return ass
        }
        if (element.direction === null || element.direction === '' || element.direction === undefined) {
          this.$Message.info('表格科目方向为空不能保存')
          ass = true
          return ass
        } else if (element.direction === 1) { // 付
          if (
            (element.payrice === null || element.payrice === 0 || element.payrice === undefined) &&
            (element.payflour === null || element.payflour === 0 || element.payflour === undefined) &&
            (element.payoil === null || element.payoil === 0 || element.payoil === undefined) &&
            (element.paybean === null || element.paybean === 0 || element.paybean === undefined)
          ) {
            this.$Message.info('重量信息不能为空，至少存在一个重量信息')
            ass = true
            return ass
          }
        } else if (element.direction === 0) { // 收
          if (
            (element.recrice === null || element.recrice === 0 || element.recrice === undefined) &&
            (element.recflour === null || element.recflour === 0 || element.recflour === undefined) &&
            (element.recoil === null || element.recoil === 0 || element.recoil === undefined) &&
            (element.recbean === null || element.recbean === 0 || element.recbean === undefined)
          ) {
            this.$Message.info('重量信息不能为空，至少存在一个重量信息')
            ass = true
            return ass
          }
        }
      })
      if (ass) {
        return
      }
      let isTrueFalse = false
      // 定义一个新数组
      const newArr = []
      this.dataTwo.forEach(element => {
        // 定义一个变量存放索引
        let index = newArr.findIndex(v => {
          return element.subjectFullName === v.name
        })
        // 判断index的值 findIndex方法找不到返回-1 找不到就新加上 找到就找到新数组中这个值的位置给他num++
        if (index === -1) {
          newArr.push({ name: element.subjectFullName, num: 1 })
        } else {
          return isTrueFalse = true
        }
      })
      if (isTrueFalse) {
        this.$Message.info('科目存在重复无法入账，请查阅')
        return
      }
      var valueData = {
        accountbookId: this.selectForm.accountbookId, // 账簿id
        isValid: 1, // 是否在用 1-在用，0-没用
        abstractType: this.subjecttype, // 摘要内容:0经费账摘要,1粮秣账摘要,2明细摘要
        subjectType: this.subjecttype, // 科目类型:0经费账科目,1粮秣账科目,2分项核算明细
        accountYear: this.selectForm.year, // 账簿年份
        certificateSn: this.selectForm.certificatesn, // 凭证号码
        isznjzflag: 0, // 智能计账标识  1是0否 2全部
        certificateDate: new Date(this.selectForm.dataTimeTwo).Format('yyyy-MM-dd'), // 入账日期  YYYY-mm-DD
        businessType: this.selectForm.businesstypeTwo, // 业务类型.可以理解为摘要
        abstractName: this.selectForm.abstractnameTwo, // 摘要内容
        department: this.selectForm.department, // 部门.比如一连队
        operatorname: this.vuex_user.base.name, // 登陆人姓名
        operatorid: this.vuex_user.base.id, // 用户id//登陆人Id
        certificatetype: 0, // 凭证类型0-普通，1-结转下年，2-上年转入
        remark: this.selectForm.remarkTwo, // 备注
        subjectDtoList: this.dataTwo
      }
      this.form.loading = true
      return new Promise((resolve) => {
        addCertificateInfo(valueData).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.dataTwo = []
            this.selectForm.abstractnameTwo = ''
            this.selectForm.remarkTwo = ''
            this.addDataTwoItem()
            this.addDataTwoItem()
            this.getAccountBookApi() // 查询活动账簿 接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 粮秣账添加按钮
    addDataTwoItem() {
      if (this.dataTwo.length > 1) {
        let ass = false
        this.dataTwo.forEach((element, index) => {
          if (element.subjectFullName === null || element.subjectFullName === '' || element.subjectFullName === undefined) {
            this.$Message.info('请先填选表格第' + (index + 1) + '条数据中的  科目名称  再进行添加科目')
            ass = true
            return ass
          }
          if (element.direction === null || element.direction === '' || element.direction === undefined) {
            this.$Message.info('请先填选表格第' + (index + 1) + '条数据中的 收（付） 再进行添加科目')
            ass = true
            return ass
          } else if (element.direction === 1) { // 付
            if (
              (element.payrice === null || element.payrice === 0 || element.payrice === undefined) &&
              (element.payflour === null || element.payflour === 0 || element.payflour === undefined) &&
              (element.payoil === null || element.payoil === 0 || element.payoil === undefined) &&
              (element.paybean === null || element.paybean === 0 || element.paybean === undefined)
            ) {
              this.$Message.info('最少输入一条重量信息，请先输入表格第' + (index + 1) + '条数据中的重量信息再进行添加科目')
              ass = true
              return ass
            }
          } else if (element.direction === 0) { // 收
            if (
              (element.recrice === null || element.recrice === 0 || element.recrice === undefined) &&
              (element.recflour === null || element.recflour === 0 || element.recflour === undefined) &&
              (element.recoil === null || element.recoil === 0 || element.recoil === undefined) &&
              (element.recbean === null || element.recbean === 0 || element.recbean === undefined)
            ) {
              this.$Message.info('最少输入一条重量信息，请先输入表格第' + (index + 1) + '条数据中的重量信息再进行添加科目')
              ass = true
              return ass
            }
          }
        })
        this.dataTwo.push(JSON.parse(JSON.stringify(this.dataTwoItem)))
        if (ass) {
          this.dataTwo.splice(this.dataTwo.length - 1, 1)
        }
      } else {
        this.dataTwo.push(JSON.parse(JSON.stringify(this.dataTwoItem)))
      }
      // this.dataTwo.push(JSON.parse(JSON.stringify(this.dataTwoItem)))
    },

    // 业务类型选择器改变回调-粮秣账
    selectModelChangeTwo() {

    },
    // 表格科目名称改变回调-粮秣账
    subjectNameTwo(index, value) {
      if (value == undefined) {
        return
      }
      this.dataTwo[index].subjectFullName = value
      this.subjectlistTwo.forEach(element => {
        if (this.dataTwo[index].subjectFullName === element.subjectfullname) {
          this.dataTwo[index].subjectId = element.subjectId
          this.dataTwo[index].subjectCode = element.subjectcode
          this.dataTwo[index].subjectName = element.subjectname
        }
      })
      // 定义一个新数组
      const newArr = []
      this.dataTwo.forEach(element => {
        // 定义一个变量存放索引
        let index = newArr.findIndex(v => {
          return element.subjectFullName === v.name
        })
        // 判断index的值 findIndex方法找不到返回-1 找不到就新加上 找到就找到新数组中这个值的位置给他num++
        if (index === -1) {
          newArr.push({ name: element.subjectFullName, num: 1 })
        } else {
          this.$Message.info('科目存在重复无法入账，请查阅')
          newArr[index].num++
        }
      })
    },
    // 表格科目方向改变回调-粮秣账
    directionTwo(index, value) {
      this.dataTwo[index].direction = value
      this.dataTwo[index].recrice = 0
      this.dataTwo[index].recflour = 0
      this.dataTwo[index].recoil = 0
      this.dataTwo[index].recbean = 0
      this.dataTwo[index].payrice = 0
      this.dataTwo[index].payflour = 0
      this.dataTwo[index].payoil = 0
      this.dataTwo[index].paybean = 0
    },
    // 收方(大米)改变回调-粮秣账
    recriceTwo(index, value) {
      this.dataTwo[index].recrice = value
    },
    // 收方(小麦粉)改变回调-粮秣账
    recflourTwo(index, value) {
      this.dataTwo[index].recflour = value
    },
    // 收方(食油)改变回调-粮秣账
    recoilTwo(index, value) {
      this.dataTwo[index].recoil = value
    },
    // 收方(大豆)改变回调-粮秣账
    recbeanTwo(index, value) {
      this.dataTwo[index].recbean = value
    },
    // 付方(大米)改变回调-粮秣账
    payriceTwo(index, value) {
      this.dataTwo[index].payrice = value
    },
    // 付方(小麦粉)改变回调-粮秣账
    payflourTwo(index, value) {
      this.dataTwo[index].payflour = value
    },
    // 付方(食油)改变回调-粮秣账
    payoilTwo(index, value) {
      this.dataTwo[index].payoil = value
    },
    // 付方(大豆)改变回调-粮秣账
    paybeanTwo(index, value) {
      this.dataTwo[index].paybean = value
    },

    // 粮秣账表格清除按钮
    clearCliTwo(index) {
      this.dataTwo.splice(index, 1)
      if (this.dataTwo.length < 2) {
        this.addDataTwoItem()
        this.$Message.info('至少存在两个科目！')
      }
      // this.zhi.splice(index, 1)
    },
    // 首页返回按钮
    returnHome() {
      this.$router.push('/home')
    }
  }
}
</script>
<style lang="less" scoped>
.topBody {
  display: flex;
  margin-bottom: 10px;
  align-items: center;
  flex-wrap: wrap;

  .topBodyItem {
    margin-right: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;

    .itemSpan {
      white-space: nowrap;
      width: 80px;
      text-align: right;
      font-size: 14px;
      color: rgba(0, 0, 0, 0.85) !important;
      margin-right: 10px;
    }

    .itemImport {
      width: 200px;
    }
  }
}

// 图表上方tabs标签样式
// 当我们需要覆盖element-ui中的样式时只能通过深度作用选择器-样式穿透
::v-deep .tableInput {
  .ivu-input-number {
    .ivu-input-number-input-wrap {
      .ivu-input-number-input {
        text-align: right;
        padding-right: 26px;
      }
    }
  }
}
</style>
